#!/bin/bash
#功能：导入国六车辆数据

#初始化环境变量
source $(cd "$(dirname "$0")"; pwd)/../../initEnv.sh
table_name=ods_cn6_car
target_table_name=ods_cn6_car
echo "导入${target_table_name}开始..."

sqoop-import \
  -D mapred.job.queue.name=hive \
  --connect $CN6_CONNECT \
  --username $CN6_USERNAME \
  --password $CN6_PASSWORD \
  --query "SELECT
             ti.vin AS vin,
             ti.gg_notice_model AS noticeModel,
             ti.pf AS emissionValue,
             terminal_no AS terminalNo,
             ti.engine_type_new AS engineModelName,
             ei.engine_model_code AS engineModelCode
            FROM
             truck_info ti
             LEFT JOIN cn6_engine_info ei ON ti.engine_type_new LIKE CONCAT( ei.engine_model_code_prefix, '%' )
             AND ti.engine_type_new LIKE CONCAT( '%', ei.engine_model_code_suffix )
            WHERE 1 =1 or $CONDITIONS" \
  --fields-terminated-by "\0001" \
  --delete-target-dir \
  --target-dir /user/root/mysql_tables/${table_name} \
  --hive-import \
  --hive-overwrite \
  --hive-table ${target_table_name} \
  --hive-database ${HIVE_DB} \
  --hive-drop-import-delims \
  --num-mappers 1 \
  --as-parquetfile;

#hive --hiveconf "tez.queue.name=hive" -e "load data inpath '/user/root/mysql_tables/${table_name}/*.parquet' OVERWRITE  into table ${HIVE_DB}.${target_table_name}"

if [ $? -ne 0 ] ; then
  echo "导入ods_cn6_car失败，耗时$((`date +%s`-START_TIME))秒..."
else
  echo "导入ods_cn6_car成功，耗时$((`date +%s`-START_TIME))秒..."
fi
